#ifndef AUX_IOINTERFACE_H
#define AUX_IOINTERFACE_H

#include "config.h"
#include "aux_types.h"
#include "aux_errno.h"
#include "aux_message.h"
#include "aux_queuemanager.h"
#include "aux_buffer.h"

typedef enum {
    IPC_PIPE_UNKNOWN = 0,
    IPC_PIPE_INIT,
    IPC_PIPE_SEND,
    IPC_PIPE_RECV,
    IPC_PIPE_BIDIRECTION,
    IPC_PIPE_BROKEN,
    IPC_PIPE_MAX
} ExIPCPipeState;

typedef struct io_pipe_t {
    TxIPCMessageClient  tClient;
    ExIPCPipeState      eState;
    TMessageManager     tMsgRecvManager;
    TxIPCBufferWithLock tDataBufLocked;
} TxIPCIOPipe;

DLL_EXPORT TxIPCIOPipe *xIPC_Pipe_Get(char *pszIp,
                                 u16   wPort,
                                 char *pszName,
                                 char *pszListenRemote);

DLL_EXPORT int xIPC_Pipe_Put(TxIPCIOPipe *ptPipe);

DLL_EXPORT int xIPC_Pipe_Send(TxIPCIOPipe *ptPipe, char *pszDest,
                                    u8 *pabyData, u32 nLen);

DLL_EXPORT int xIPC_Pipe_Read(TxIPCIOPipe *ptPipe,
                                    u8 *pabyBuffer, u32 nWantLen);

DLL_EXPORT int xIPC_Pipe_GetSendingToRemoteStatus(TxIPCIOPipe *ptPipe);

DLL_EXPORT int xIPC_Pipe_GetRecvingFromRemoteStatus(TxIPCIOPipe *ptPipe);

DLL_EXPORT int xIPC_Pipe_Wait(TxIPCIOPipe *ptPipe, u8 *pabyBuffer,
                        u32 nWantLen, u32 nTimeoutMs);

DLL_EXPORT TxIPCMessageRouter *xIPC_Router_Get(char *pszIp, u16 wPort, char *pszName);

DLL_EXPORT int xIPC_Router_Put(TxIPCMessageRouter *ptRouter);

EErrNo xIPCCoreIOInterfaceInit();

EErrNo xIPCCoreIOInterfaceDeinit();

#endif
